package org.monkey.common.cbs.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.Data;

@Data
public class PageConvertUtil {
  public static <T, R> IPage<R> convert(IPage<T> page, Function<T, R> function) {
    List<T> ts = page.getRecords();
    List<R> rs = ts.stream().map(function).collect(Collectors.toList());
    Page<R> prs = new Page<>();
    // todo 复制page其它属性
    prs.setRecords(rs);
    return prs;
  }
}
